package com.qf.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author zhaojian
 */
@RestController
@RequestMapping("/origin")
@CrossOrigin(methods = RequestMethod.GET)//允许来自8081服务器发来的请求
public class OriginController {

    @RequestMapping("/test1")
    public String test1(HttpSession session, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Cache-Control","no-cache");

        System.out.println("test1~~");
        session.setAttribute("name","shine");
        return "ok";
    }

    @RequestMapping("/test2")
    public String test2(HttpSession session){
        System.out.println("test2~~");
        String name = (String)session.getAttribute("name");
        System.out.println("name:"+name);
        return "ok";
    }
}